package com.aurora.source.home.presenter;

import android.content.Context;

import com.aurora.source.base.BaseBean;
import com.aurora.source.base.BasePresenter;
import com.aurora.source.constant.AuroraConstants;
import com.aurora.source.home.bean.BatchManagementBean;
import com.aurora.source.home.view.IBatchManagementView;
import com.aurora.source.util.netutil.SubscriberObserver;

import java.util.Map;

public class BatchManagementPresenter extends BasePresenter<IBatchManagementView> {
    public BatchManagementPresenter(IBatchManagementView baseView) {
        super(baseView);
    }

    /**
     *
     * @param context
     * @param params
     * @param batchType 0查询全部，1启动的批次
     */
    public void batchManagement(Context context, Map<String, String> params,String batchType) {
        params.put("batchType",batchType);
        requestMethod.batchManagement(params, new SubscriberObserver<BaseBean<BatchManagementBean>>(context,"正在加载...") {
            @Override
            public void onSuccess(BaseBean<BatchManagementBean> batchManagementBeanBaseBean) {
                if (batchManagementBeanBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)) {
                    baseView.onBatchManagementSuccess(batchManagementBeanBaseBean.getData());
                } else {
                    baseView.onBatchManagementFail(batchManagementBeanBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onBatchManagementFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }

    public void changeBatchNameOrState(Map<String, String> params) {

        requestMethod.changeBatchNameOrState(params, new SubscriberObserver<BaseBean>((Context)baseView,"数据请求中...") {
            @Override
            public void onSuccess(BaseBean batchManagementBeanBaseBean) {
                if (batchManagementBeanBaseBean.getCode().equals(AuroraConstants.REQUEST_SUCCESS)) {
                    baseView.onChangeSuccess(batchManagementBeanBaseBean.getMsg());
                } else {
                    baseView.onChangeFail(batchManagementBeanBaseBean.getMsg());
                }
            }

            @Override
            public void onError(String msg) {
                baseView.onChangeFail(msg);
            }

            @Override
            public void onFinish() {

            }
        });
    }
}
